﻿using Kaskelot.SP.Core;
using System;
using System.Threading;

namespace Kaskelot.SP.Services.Client
{
	public abstract class BaseClientService
	{
		public BaseClientService()
		{
			Logger.LogVerbose(this, LayerNames.ClientService, "ctor", "Setting culture to Swedish");
			Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(1053);
		}

		internal void HandleAccessDenied<T>(Model.Client.ClientServiceResult<T> result)
		{
			result.ErrorMessage = "";
			result.HasError = true;
		}

		internal void HandleGeneralError<T>(Model.Client.ClientServiceResult<T> result, Exception error, string methodName, string messageToClient)
		{
			Logger.LogError(this, LayerNames.ClientService, methodName, "Error", error);
			result.HasError = true;
			result.ErrorMessage = string.Format("{0}.\n Ange felid {1} vid rapportering",
				messageToClient,
				Logger.GetCurrentCorrelationID());
		}
	}
}
